package com.myjava.linkedhashset;

import java.util.TreeSet;

class Person1 implements Comparable<Person1>{
      String name;

    @Override
    public int compareTo(Person1 o) {
        int num = this.age-o.age;
        return 0==num?this.name.compareTo(o.name):num;
//        if(0==num){
//            return  this.name.compareTo(o.name);
//        }else{
//            return num;
//
//        }
    }

    int age;
    Person1(String name,int age){
        this.name=name;
        this.age=age;
    }

    @Override
    public String toString() {
        return "Person1{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class TreeSetdemo {
    public static void main(String[] args) {
        Person1 p1 = new Person1("zs",18);
        Person1 p2 = new Person1("zd",15);
        Person1 p3 = new Person1("zw",11);
        Person1 p4 = new Person1("zh",15);
      TreeSet<Person1> ts =  new TreeSet<Person1>();
      ts.add(p1);
      ts.add(p2);
      ts.add(p3);
      ts.add(p4);
        System.out.println(ts);
    }
}
